<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Examples</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Chapter 1. Boost.Beast">
<link rel="up" href="../index.html" title="Chapter 1. Boost.Beast">
<link rel="prev" href="quick_start/websocket_autobahn_testsuite.html" title="WebSocket (Autobahn|Testsuite)">
<link rel="next" href="using_io.html" title="Networking">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="quick_start/websocket_autobahn_testsuite.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="using_io.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="beast.examples"></a><a class="link" href="examples.html" title="Examples">Examples</a>
</h2></div></div></div>
<p>
      Source code and build scripts for these programs are located in the <a href="../../../example" target="_top">example</a> directory.
    </p>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="beast.examples.clients"></a><a class="link" href="examples.html#beast.examples.clients" title="Clients">Clients</a>
</h3></div></div></div>
<p>
        These HTTP clients submit a GET request to a server specified on the command
        line, and prints the resulting response. The crawl client asynchronously
        fetches the document root of the 10,000 top ranked domains, this may be used
        to evaluate robustness. All asynchronous clients support timeouts.
      </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                <p>
                  Description
                </p>
              </th>
<th>
                <p>
                  Source File
                </p>
              </th>
<th>
                <p>
                  Source File (using SSL)
                </p>
              </th>
</tr></thead>
<tbody>
<tr>
<td>
                <p>
                  HTTP, synchronous
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/http/client/sync/http_client_sync.cpp" target="_top">http_client_sync.cpp</a>
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/http/client/sync-ssl/http_client_sync_ssl.cpp" target="_top">http_client_sync_ssl.cpp</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  HTTP, asynchronous
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/http/client/async/http_client_async.cpp" target="_top">http_client_async.cpp</a>
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/http/client/async-ssl/http_client_async_ssl.cpp" target="_top">http_client_async_ssl.cpp</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  HTTP, asynchronous using <a href="../../../../../doc/html/boost_asio/reference/system_executor.html" target="_top"><code class="computeroutput"><span class="identifier">net</span><span class="special">::</span><span class="identifier">system_executor</span></code></a>
                </p>
              </td>
<td>
              </td>
<td>
                <p>
                  <a href="../../../example/http/client/async-ssl-system-executor/http_client_async_ssl_system_executor.cpp" target="_top">http_client_async_ssl_system_executor.cpp</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  HTTP, coroutine
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/http/client/coro/http_client_coro.cpp" target="_top">http_client_coro.cpp</a>
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/http/client/coro-ssl/http_client_coro_ssl.cpp" target="_top">http_client_coro_ssl.cpp</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  HTTP crawl (asynchronous)
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/http/client/crawl/http_crawl.cpp" target="_top">http_crawl.cpp</a>
                </p>
              </td>
<td>
              </td>
</tr>
</tbody>
</table></div>
<p>
        These WebSocket clients connect to a server and send a message, then receive
        a message and print the response before disconnecting. All asynchronous clients
        support timeouts.
      </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                <p>
                  Description
                </p>
              </th>
<th>
                <p>
                  Source File
                </p>
              </th>
<th>
                <p>
                  Source File (using SSL)
                </p>
              </th>
</tr></thead>
<tbody>
<tr>
<td>
                <p>
                  WebSocket, synchronous
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/client/sync/websocket_client_sync.cpp" target="_top">websocket_client_sync.cpp</a>
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/client/sync-ssl/websocket_client_sync_ssl.cpp" target="_top">websocket_client_sync_ssl.cpp</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  WebSocket, asynchronous
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/client/async/websocket_client_async.cpp" target="_top">websocket_client_async.cpp</a>
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/client/async-ssl/websocket_client_async_ssl.cpp" target="_top">websocket_client_async_ssl.cpp</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  WebSocket, asynchronous using <a href="../../../../../doc/html/boost_asio/reference/system_executor.html" target="_top"><code class="computeroutput"><span class="identifier">net</span><span class="special">::</span><span class="identifier">system_executor</span></code></a>
                </p>
              </td>
<td>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/client/async-ssl-system-executor/websocket_client_async_ssl_system_executor.cpp" target="_top">websocket_client_async_ssl_system_executor.cpp</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  WebSocket, coroutine
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/client/coro/websocket_client_coro.cpp" target="_top">websocket_client_coro.cpp</a>
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/client/coro-ssl/websocket_client_coro_ssl.cpp" target="_top">websocket_client_coro_ssl.cpp</a>
                </p>
              </td>
</tr>
</tbody>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="beast.examples.servers"></a><a class="link" href="examples.html#beast.examples.servers" title="Servers">Servers</a>
</h3></div></div></div>
<p>
        These HTTP servers deliver files from a root directory specified on the command
        line. All asynchronous servers support timeouts.
      </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                <p>
                  Description
                </p>
              </th>
<th>
                <p>
                  Source File
                </p>
              </th>
<th>
                <p>
                  Source File (using SSL)
                </p>
              </th>
</tr></thead>
<tbody>
<tr>
<td>
                <p>
                  HTTP, synchronous
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/http/server/sync/http_server_sync.cpp" target="_top">http_server_sync.cpp</a>
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/http/server/sync-ssl/http_server_sync_ssl.cpp" target="_top">http_server_sync_ssl.cpp</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  HTTP, asynchronous
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/http/server/async/http_server_async.cpp" target="_top">http_server_async.cpp</a>
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/http/server/async-ssl/http_server_async_ssl.cpp" target="_top">http_server_async_ssl.cpp</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  HTTP, coroutine
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/http/server/coro/http_server_coro.cpp" target="_top">http_server_coro.cpp</a>
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/http/server/coro-ssl/http_server_coro_ssl.cpp" target="_top">http_server_coro_ssl.cpp</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  HTTP, stackless coroutine
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/http/server/stackless/http_server_stackless.cpp" target="_top">http_server_stackless.cpp</a>
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/http/server/stackless-ssl/http_server_stackless_ssl.cpp" target="_top">http_server_stackless_ssl.cpp</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  HTTP, fast (optimized for speed)
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/http/server/fast/http_server_fast.cpp" target="_top">http_server_fast.cpp</a>
                </p>
              </td>
<td>
              </td>
</tr>
<tr>
<td>
                <p>
                  HTTP, small (optimized for space)
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/http/server/small/http_server_small.cpp" target="_top">http_server_small.cpp</a>
                </p>
              </td>
<td>
              </td>
</tr>
<tr>
<td>
                <p>
                  HTTP, flex (plain + SSL)
                </p>
              </td>
<td>
              </td>
<td>
                <p>
                  <a href="../../../example/http/server/flex/http_server_flex.cpp" target="_top">http_server_flex.cpp</a>
                </p>
              </td>
</tr>
</tbody>
</table></div>
<p>
        These WebSocket servers echo back any message received, keeping the session
        open until the client disconnects. All asynchronous servers support timeouts.
      </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                <p>
                  Description
                </p>
              </th>
<th>
                <p>
                  Source File
                </p>
              </th>
<th>
                <p>
                  Source File (using SSL)
                </p>
              </th>
</tr></thead>
<tbody>
<tr>
<td>
                <p>
                  WebSocket, synchronous
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/server/sync/websocket_server_sync.cpp" target="_top">websocket_server_sync.cpp</a>
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/server/sync-ssl/websocket_server_sync_ssl.cpp" target="_top">websocket_server_sync_ssl.cpp</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  WebSocket, asynchronous
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/server/async/websocket_server_async.cpp" target="_top">websocket_server_async.cpp</a>
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/server/async-ssl/websocket_server_async_ssl.cpp" target="_top">websocket_server_async_ssl.cpp</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  WebSocket, coroutine
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/server/coro/websocket_server_coro.cpp" target="_top">websocket_server_coro.cpp</a>
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/server/coro-ssl/websocket_server_coro_ssl.cpp" target="_top">websocket_server_coro_ssl.cpp</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  WebSocket, stackless coroutine
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/server/stackless/websocket_server_stackless.cpp" target="_top">websocket_server_stackless.cpp</a>
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/server/stackless-ssl/websocket_server_stackless_ssl.cpp" target="_top">websocket_server_stackless_ssl.cpp</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  WebSocket, fast (suited for benchmarks)
                </p>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/server/fast/websocket_server_fast.cpp" target="_top">websocket_server_fast.cpp</a>
                </p>
              </td>
<td>
              </td>
</tr>
</tbody>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="beast.examples.servers_advanced"></a><a class="link" href="examples.html#beast.examples.servers_advanced" title="Servers (Advanced)">Servers (Advanced)</a>
</h3></div></div></div>
<p>
        These servers offer both HTTP and WebSocket services on the same port, and
        illustrate the implementation of advanced features.
      </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                <p>
                  Description
                </p>
              </th>
<th>
                <p>
                  Features
                </p>
              </th>
<th>
                <p>
                  Sources
                </p>
              </th>
</tr></thead>
<tbody>
<tr>
<td>
                <p>
                  Advanced
                </p>
              </td>
<td>
                <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
                      Timeouts
                    </li>
<li class="listitem">
                      Multi-threaded
                    </li>
<li class="listitem">
                      HTTP pipelining
                    </li>
<li class="listitem">
                      Parser-oriented HTTP reading
                    </li>
<li class="listitem">
                      Dual protocols: HTTP and WebSocket
                    </li>
<li class="listitem">
                      Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)
                    </li>
</ul></div>
              </td>
<td>
                <p>
                  <a href="../../../example/advanced/server/advanced_server.cpp" target="_top">advanced_server.cpp</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  Advanced, flex (plain + SSL)
                </p>
              </td>
<td>
                <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
                      Timeouts
                    </li>
<li class="listitem">
                      Multi-threaded
                    </li>
<li class="listitem">
                      HTTP pipelining
                    </li>
<li class="listitem">
                      Parser-oriented HTTP reading
                    </li>
<li class="listitem">
                      Dual protocols: HTTP and WebSocket
                    </li>
<li class="listitem">
                      Flexible ports: plain and SSL on the same port
                    </li>
<li class="listitem">
                      Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)
                    </li>
</ul></div>
              </td>
<td>
                <p>
                  <a href="../../../example/advanced/server-flex/advanced_server_flex.cpp" target="_top">advanced_server_flex.cpp</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  Chat Server, multi-threaded
                </p>
              </td>
<td>
                <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
                      Multi-threaded
                    </li>
<li class="listitem">
                      Broadcasting Messages
                    </li>
<li class="listitem">
                      Multi-user Chat Server
                    </li>
<li class="listitem">
                      JavaScript Browser Client
                    </li>
<li class="listitem">
                      Parser-oriented HTTP reading
                    </li>
<li class="listitem">
                      Dual protocols: HTTP and WebSocket
                    </li>
<li class="listitem">
                      Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)
                    </li>
</ul></div>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/server/chat-multi" target="_top">chat-multi</a>
                </p>
              </td>
</tr>
</tbody>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="beast.examples.chat_server"></a><a class="link" href="examples.html#beast.examples.chat_server" title="Chat Server 🎦">Chat Server 🎦</a>
</h3></div></div></div>
<p>
        This example demonstrates a websocket chat server, allowing multiple users
        to connect and participate in live, group messaging. It comes with a tiny
        front end implemented in JavaScript and HTML5 which runs in any browser.
        The example is accompanied by a one hour presentation which provides a discussion
        of networking concepts, followed by in-depth explanation of how the client
        and server are constructed. This talk was delivered at <a href="https://cppcon.org" target="_top">CppCon
        2018</a>. The source code in the Beast example contains improvements
        to the original program.
      </p>
<div class="table">
<a name="beast.examples.chat_server.chat_websocket_server_and_javasc"></a><p class="title"><b>Table 1.1. Chat WebSocket Server and JavaScript Client</b></p>
<div class="table-contents"><table class="table" summary="Chat WebSocket Server and JavaScript Client">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                <p>
                  Component
                </p>
              </th>
<th>
                <p>
                  Features
                </p>
              </th>
<th>
                <p>
                  Sources
                </p>
              </th>
</tr></thead>
<tbody>
<tr>
<td>
                <p>
                  Server
                </p>
              </td>
<td>
                <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
                      C++
                    </li>
<li class="listitem">
                      Timeouts
                    </li>
<li class="listitem">
                      Multi-threaded
                    </li>
<li class="listitem">
                      Broadcast to multiple peers
                    </li>
<li class="listitem">
                      Dual protocols: HTTP and WebSocket
                    </li>
<li class="listitem">
                      Clean exit via SIGINT (CTRL+C) or SIGTERM (kill)
                    </li>
</ul></div>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/server/chat-multi" target="_top">chat-multi</a>
                </p>
              </td>
</tr>
<tr>
<td>
                <p>
                  Client
                </p>
              </td>
<td>
                <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
                      JavaScript / HTML5
                    </li>
<li class="listitem">
                      Runs in the browser
                    </li>
<li class="listitem">
                      Delivered by the server
                    </li>
<li class="listitem">
                      Only 60 lines total including UI
                    </li>
<li class="listitem">
                      Completely portable graphics
                    </li>
</ul></div>
              </td>
<td>
                <p>
                  <a href="../../../example/websocket/server/chat-multi/chat_client.html" target="_top">chat_client.html</a>
                </p>
              </td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>
        </p>
<div class="mediaobject"><embed src="https://www.youtube.com/embed/7FQwAjELMek" align="middle" width="560" height="315"></embed></div>
<p>
      </p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2016-2019 Vinnie
      Falco<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="quick_start/websocket_autobahn_testsuite.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="using_io.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
